<template>
  <div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
      <div class="widget am-cf">
        <div class="widget-head am-cf">
          <div class="widget-title  am-cf">发票使用情况</div>
        </div>
        <div class="widget-body  am-fr">
          <div class="am-u-sm-12 am-form ">
            <!-- <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
              <div class="am-form-group">
                <select2  v-model="query.areaTeamId" :options="areaTeams">
                  <option value="">区域</option>
                </select2>
              </div>
            </div> -->
            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
              <div class="am-form-group">
                <select2  v-model="query.invoiceType">
                  <option value="">开票类型</option>
                  <option value="1">正票</option>
                  <option value="2">红冲</option>
                </select2>
              </div>
            </div>

            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
              <div class="am-form-group">
                <input type="text" v-model="query.studentName" placeholder="请输入学生姓名"/>
              </div>
            </div>
            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
              <div class="am-form-group">
                <input type="text" v-model="query.studentPhoneNo" placeholder="请输入学生电话"/>
              </div>
            </div>
            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
              <div class="am-form-group">
                 <input type="text" v-model="query.operatorName" placeholder="请输入操作人"/>
              </div>
            </div>

            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
              <div class="am-form-group">
                <el-date-picker
                    v-model="query.operateTime"
                    type="daterange"
                    placeholder="操作时间">
                </el-date-picker>
              </div>
            </div>
            <div class="am-u-sm-12 am-u-md-12 am-u-lg-6 am-u-end">
              <div class="am-form-group">
                <button type="button" class="am-btn am-btn-default am-btn-success"
                        @click="search" ><span class="am-icon-search"></span>查询
                </button>
                <button type="button" class="am-btn am-btn-default am-btn-success"
                        @click="exportExcel" ><span class="am-icon-download"></span>导出excel
                </button>
              </div>
            </div>


          </div>

          <div class="am-u-sm-12">
            <el-table
              :data="tableData"
              border
              stripe
              style="min-width: 100%">
              <el-table-column
                prop="invoiceId"
                label="发票流水号"
                min-width="150">
              </el-table-column>
              <el-table-column
                prop="taxTotalAmount"
                label="价税合计金额"
                min-width="150">
              </el-table-column>
              <el-table-column
                label="开票类型"
                min-width="100">
                <template scope="scope">
                    <span>{{scope.row.invoiceType==1?'正票':'红冲'}}</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="studentName"
                label="学生姓名"
                min-width="100">
              </el-table-column>

              <el-table-column
                prop="studentPhoneNo"
                label="学生电话"
                min-width="150">
              </el-table-column>
              <el-table-column
                label="操作人"
                prop="operatorName"
                min-width="100">
                </el-table-column>
              <el-table-column
                label="操作时间"
                min-width="100">
                <template scope="scope">
                  {{scope.row.updateTime | formatTime}}
                </template>
              </el-table-column>


            </el-table>
          </div>
          <div class="am-u-lg-12 am-cf">

            <div class="am-fr">
              <pagination v-bind:total="total" v-bind:pageNo="pageNo" v-bind:pageSize="pageSize"
                          @paging="handlePage"/>
            </div>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>
<script>
  import io from '../../lib/io'
  import Pagination from '../base/Pagination.vue'
  import util from '../../lib/util'
  import moment from 'moment'

  export default{
    components: {Pagination},
    data: function () {
      return {
        tableData: [],
        pageNo: 1,
        pageSize: 20,
        total: 0,
        query: {
            // areaTeamId:"",
            invoiceType:"",
            studentName:"",
            studentPhoneNo:"",
            startDate:"",
            endDate:"",
            operateTime:[],
        },

      }
    },
    computed: {
      areaTeams: function () {
        var options = ( this.$root.config.areaTeams || [] )
          .map(function (item) {
            return {value: item.areaTeamId, text: item.name}
          })
        return options
      },
    },
    mounted: function () {
      $(window).smoothScroll()
    },
    created: function () {
      this.loadTableData(this.pageNo)

    },

    methods: {
      search: function () {
        this.loadTableData(1)
      },
      loadTableData(pageNo){
        // var _this = this
        this.pageNo = pageNo || this.pageNo || 1

        let param = {...this.query}
        console.log(this.query.operateTime)
        if(this.query.operateTime[0]){
            param.startDate = util.formatDate(this.query.operateTime[0])+' 00:00:00'
            param.endDate = util.formatDate(this.query.operateTime[1])+' 23:59:59'
        }else{
            param.startDate = ''
            param.endDate = ''
        }
        this.$showLoading()
        io.post(io.findStudentClassInvoicePage,Object.assign (param,{pageNo:this.pageNo,pageSize:this.pageSize,}), (ret)=> {
          this.$hiddenLoading()
          if (ret.success) {
            this.total = ret.data.total
            this.tableData = ret.data.list
          } else {
            this.$alert(ret.desc)
          }
        })
      },
      handlePage(pageNo) {
        this.pageNo = pageNo || this.pageNo || 1
        this.loadTableData(this.pageNo)
      },
      exportExcel:function(){
        let param = {...this.query}
        if(this.query.operateTime[0]){
            param.startDate = util.formatDate(this.query.operateTime[0])+' 00:00:00'
            param.endDate = util.formatDate(this.query.operateTime[1])+' 23:59:59'
        }else{
            param.startDate = ''
            param.endDate = ''
        }
        io.downloadFile(io.exportStudentClassInvoice,param)
      }
    }
  }
</script>
